package HomeWork20241215.GirlFriend;

import java.util.Scanner;

/*
 * 要求1：计算出四女朋友的平均年龄
 * 要求2：统计年龄比平均值低的女朋友有几个？并把她们的所有信息打印出来。
 * */
public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        GirlFriend[] gfs = new GirlFriend[4];

        for (int i = 0; i < gfs.length; i++) {
            System.out.println("请输入第" + (i + 1) + "女朋友的信息：");
            System.out.print("姓名:");
            String name = scanner.nextLine();
            System.out.print("年龄:");
            int age = Integer.parseInt(scanner.nextLine());
            System.out.println("性别:");
            String gender = scanner.nextLine();
            System.out.println("兴趣爱好:");
            String hobby = scanner.nextLine();

            gfs[i] = new GirlFriend(name, age, gender, hobby);
        }

        double sum = 0;
        System.out.println("所有女朋友的信息如下：");
        for (GirlFriend gf : gfs) {
            System.out.println(gf.toString());
            sum += gf.getAge();
        }
        double avg = sum / gfs.length;
        System.out.println(gfs.length + "个女朋友平均年龄为：" + avg);
        int count = 0;
        System.out.println("年龄低于平均值的女朋友的信息如下：");
        for (GirlFriend gf : gfs) {
            if (gf.getAge() < avg) {
                count++;
                System.out.println(gf.toString());
            }
        }
        System.out.println("年龄低于平均值的女朋友有：" + count + "个");
    }
}
